package com.kailong.servlet.student;

import cn.hutool.core.date.DateUtil;
import com.kailong.dao.ManageReserve;

import java.util.*;

public class ReserveTimeJudge {
    /**
     *判断能不能预约，时间区间的判断
     * @param startTime
     * @param endTime
     */
    public static boolean judgeTime(String startTime,String endTime){
        HashMap<String,String> timeMap = new HashMap<>();

        timeMap = ManageReserve.select("21001");
        boolean isReserve  = true;
        Set<Map.Entry<String, String>> entries = timeMap.entrySet();
        String start = startTime;
        String end = endTime;
        Date startTime1 = DateUtil.parse(start);
        Date endTime1 = DateUtil.parse(end);
        Set set = timeMap.keySet();
        Iterator iterator = set.iterator();
        while (iterator.hasNext()){
            Object key = iterator.next();
            Object value = timeMap.get(key);
            Date startTime2 = DateUtil.parse((String)key);
            Date endTime2 = DateUtil.parse((String)value);
            if ((startTime1.compareTo(startTime2)>0)&&(endTime1.compareTo(endTime2)<0)){
               isReserve = false;
            }
        }
        return isReserve;
    }
}
